package com.ruoyi.framework.web.service;

import com.ruoyi.common.core.domain.model.LoginBody;
import com.ruoyi.framework.web.service.proxy.LoginFlow;
import org.springframework.stereotype.Component;
import com.ruoyi.common.exception.ServiceException;

/**
 * 登录校验方法
 *
 * @author ruoyi
 */
@Component
public class SysLoginService {

    /**
     * 登录验证
     *
     * @param loginBody 请求体
     *                  param username 用户名
     *                  param password 密码
     *                  param code     验证码
     *                  param uuid     唯一标识
     * @return 登录成功的token
     */
    public String login(LoginBody loginBody) {
        //执行登录
        String loginType = loginBody.getLoginType();
        LoginFlow loginFlow = LoginFlow.getInstance(loginType);
        if (loginFlow == null) {
            throw new ServiceException("无效的登录类型");
        }
        //执行登录
        return loginFlow.execFlow(loginBody);
    }
}
